package test2;

import java.math.BigInteger;

public class RabinTest {
    public static void main(String[] args) {
        RabinKeyGenerator keyGenerator = new RabinKeyGenerator();
        BigInteger n = keyGenerator.getPublicKey();
        BigInteger[] privateKey = keyGenerator.getPrivateKey();
        BigInteger p = privateKey[0];
        BigInteger q = privateKey[1];

        System.out.println("公钥 n: " + n);
        System.out.println("私钥 p: " + p);

        BigInteger m = new BigInteger("24215250306"); // 明文
        System.out.println("明文 m: " + m);

        BigInteger c = RabinEncryptor.encrypt(m, n); // 加密
        System.out.println("密文 c: " + c);

        BigInteger[] possibleMessages = RabinDecryptor.decrypt(c, p, q); // 解密

        System.out.println("可能的明文:");
        for (BigInteger msg : possibleMessages) {
            System.out.println(msg);
        }
    }
}
